package com.boy.rpc.framework.console.workbench;


import com.boy.rpc.framework.console.workbench.constant.WebConstant;

/**
 * 平台响应结果
 */
public class WorkbenchResult implements WebConstant {

	private String resultCode; //200 success   500 server-error 600 business-exception

	private String resultMsg;  //detail

	private Object data;       //attachment

	private WorkbenchCodeEnum codeEnum;//error-code-msg enum

	private WorkbenchResult() {

	}

	private WorkbenchResult(String resultCode, String resultMsg, Object data, WorkbenchCodeEnum codeEnum) {
		this.resultCode = resultCode;
		this.resultMsg = resultMsg;
		this.data = data;
		this.codeEnum = codeEnum;
	}
	
	public String getResultCode() {
		return resultCode;
	}

	public String getResultMsg() {
		return resultMsg;
	}

	public Object getData() {
		return data;
	}

	public WorkbenchCodeEnum getCodeEnum() {
		return codeEnum;
	}

	public void setCodeEnum(WorkbenchCodeEnum codeEnum) {
		this.codeEnum = codeEnum;
	}
	
	public static Builder custom() {
		return new Builder();
	}
	
	public static class Builder {
		
		private String resultCode; //200  SUCCESS200    500server-error  ERROR500  600business-exception  BUSINESSEXCEPTION600
		
		private String resultMsg;  //detail
		
		private Object data;       //attachment
		
		private WorkbenchCodeEnum codeEnum;//error-code-msg enum
		
		Builder() {
			resultCode = SUCCESS200;
			resultMsg = "request success";
			data = "null";
			codeEnum = WorkbenchCodeEnum.valueOf(OK_SUCCESS);
		}
		
		public Builder setOK(WorkbenchCodeEnum codeEnum, Object data) {
			resultCode = SUCCESS200;
			resultMsg = "request success";
			this.data=data;
			this.codeEnum = codeEnum;
			return this;
		}
		
		public Builder setOK(WorkbenchCodeEnum codeEnum) {
			resultCode = SUCCESS200;
			resultMsg = "request success";
			this.data=null;
			this.codeEnum = codeEnum;
			return this;
		}
		
		public Builder setNO(WorkbenchCodeEnum codeEnum) {
			resultCode = EXCEPTION600;
			resultMsg = "business exception";
			this.data=null;
			this.codeEnum = codeEnum;
			return this;
		}
		
		public WorkbenchResult build() {
			return new WorkbenchResult(resultCode, resultMsg, data, codeEnum);
		}
		
	}
}
